csr_constants = {
    'fast_a_iir_c_1_shift': 23,
    'fast_a_iir_c_1_width': 25,
    'fast_a_iir_c_1_interval': 1,
    'fast_a_iir_c_1_latency': 2,
    'fast_a_iir_c_1_order': 1,
    'fast_a_iir_c_1_iterative': 0,
    'fast_a_iir_d_1_shift': 23,
    'fast_a_iir_d_1_width': 25,
    'fast_a_iir_d_1_interval': 1,
    'fast_a_iir_d_1_latency': 3,
    'fast_a_iir_d_1_order': 2,
    'fast_a_iir_d_1_iterative': 0,
    'fast_a_iir_c_2_shift': 23,
    'fast_a_iir_c_2_width': 25,
    'fast_a_iir_c_2_interval': 1,
    'fast_a_iir_c_2_latency': 2,
    'fast_a_iir_c_2_order': 1,
    'fast_a_iir_c_2_iterative': 0,
    'fast_a_iir_d_2_shift': 23,
    'fast_a_iir_d_2_width': 25,
    'fast_a_iir_d_2_interval': 1,
    'fast_a_iir_d_2_latency': 3,
    'fast_a_iir_d_2_order': 2,
    'fast_a_iir_d_2_iterative': 0,
    'fast_b_iir_c_1_shift': 23,
    'fast_b_iir_c_1_width': 25,
    'fast_b_iir_c_1_interval': 1,
    'fast_b_iir_c_1_latency': 2,
    'fast_b_iir_c_1_order': 1,
    'fast_b_iir_c_1_iterative': 0,
    'fast_b_iir_d_1_shift': 23,
    'fast_b_iir_d_1_width': 25,
    'fast_b_iir_d_1_interval': 1,
    'fast_b_iir_d_1_latency': 3,
    'fast_b_iir_d_1_order': 2,
    'fast_b_iir_d_1_iterative': 0,
    'fast_b_iir_c_2_shift': 23,
    'fast_b_iir_c_2_width': 25,
    'fast_b_iir_c_2_interval': 1,
    'fast_b_iir_c_2_latency': 2,
    'fast_b_iir_c_2_order': 1,
    'fast_b_iir_c_2_iterative': 0,
    'fast_b_iir_d_2_shift': 23,
    'fast_b_iir_d_2_width': 25,
    'fast_b_iir_d_2_interval': 1,
    'fast_b_iir_d_2_latency': 3,
    'fast_b_iir_d_2_order': 2,
    'fast_b_iir_d_2_iterative': 0,
    'logic_raw_acquisition_iir_shift': 23,
    'logic_raw_acquisition_iir_width': 25,
    'logic_raw_acquisition_iir_interval': 1,
    'logic_raw_acquisition_iir_latency': 6,
    'logic_raw_acquisition_iir_order': 5,
    'logic_raw_acquisition_iir_iterative': 0,
}

csr = {
    'dna_dna': (28, 0x000, 64, False),
    'fast_a_y_tap': (0, 0x000, 2, True),
    'fast_a_invert': (0, 0x001, 1, True),
    'fast_a_demod_delay': (0, 0x002, 32, True),
    'fast_a_demod_multiplier': (0, 0x006, 4, True),
    'fast_a_x_limit_1_min': (0, 0x007, 25, True),
    'fast_a_x_limit_1_max': (0, 0x00b, 25, True),
    'fast_a_iir_c_1_z0': (0, 0x00f, 27, True),
    'fast_a_iir_c_1_a1': (0, 0x013, 25, True),
    'fast_a_iir_c_1_b0': (0, 0x017, 25, True),
    'fast_a_iir_c_1_b1': (0, 0x01b, 25, True),
    'fast_a_iir_d_1_z0': (0, 0x01f, 27, True),
    'fast_a_iir_d_1_a1': (0, 0x023, 25, True),
    'fast_a_iir_d_1_a2': (0, 0x027, 25, True),
    'fast_a_iir_d_1_b0': (0, 0x02b, 25, True),
    'fast_a_iir_d_1_b1': (0, 0x02f, 25, True),
    'fast_a_iir_d_1_b2': (0, 0x033, 25, True),
    'fast_a_y_limit_1_min': (0, 0x037, 25, True),
    'fast_a_y_limit_1_max': (0, 0x03b, 25, True),
    'fast_a_x_limit_2_min': (0, 0x03f, 25, True),
    'fast_a_x_limit_2_max': (0, 0x043, 25, True),
    'fast_a_iir_c_2_z0': (0, 0x047, 27, True),
    'fast_a_iir_c_2_a1': (0, 0x04b, 25, True),
    'fast_a_iir_c_2_b0': (0, 0x04f, 25, True),
    'fast_a_iir_c_2_b1': (0, 0x053, 25, True),
    'fast_a_iir_d_2_z0': (0, 0x057, 27, True),
    'fast_a_iir_d_2_a1': (0, 0x05b, 25, True),
    'fast_a_iir_d_2_a2': (0, 0x05f, 25, True),
    'fast_a_iir_d_2_b0': (0, 0x063, 25, True),
    'fast_a_iir_d_2_b1': (0, 0x067, 25, True),
    'fast_a_iir_d_2_b2': (0, 0x06b, 25, True),
    'fast_a_y_limit_2_min': (0, 0x06f, 25, True),
    'fast_a_y_limit_2_max': (0, 0x073, 25, True),
    'fast_a_x_clr': (0, 0x077, 1, True),
    'fast_a_x_max': (0, 0x078, 25, False),
    'fast_a_x_min': (0, 0x07c, 25, False),
    'fast_a_out_i_clr': (0, 0x080, 1, True),
    'fast_a_out_i_max': (0, 0x081, 25, False),
    'fast_a_out_i_min': (0, 0x085, 25, False),
    'fast_a_out_q_clr': (0, 0x089, 1, True),
    'fast_a_out_q_max': (0, 0x08a, 25, False),
    'fast_a_out_q_min': (0, 0x08e, 25, False),
    'fast_a_dx_sel': (0, 0x092, 4, True),
    'fast_a_dy_sel': (0, 0x093, 4, True),
    'fast_b_y_tap': (1, 0x000, 2, True),
    'fast_b_invert': (1, 0x001, 1, True),
    'fast_b_demod_delay': (1, 0x002, 32, True),
    'fast_b_demod_multiplier': (1, 0x006, 4, True),
    'fast_b_x_limit_1_min': (1, 0x007, 25, True),
    'fast_b_x_limit_1_max': (1, 0x00b, 25, True),
    'fast_b_iir_c_1_z0': (1, 0x00f, 27, True),
    'fast_b_iir_c_1_a1': (1, 0x013, 25, True),
    'fast_b_iir_c_1_b0': (1, 0x017, 25, True),
    'fast_b_iir_c_1_b1': (1, 0x01b, 25, True),
    'fast_b_iir_d_1_z0': (1, 0x01f, 27, True),
    'fast_b_iir_d_1_a1': (1, 0x023, 25, True),
    'fast_b_iir_d_1_a2': (1, 0x027, 25, True),
    'fast_b_iir_d_1_b0': (1, 0x02b, 25, True),
    'fast_b_iir_d_1_b1': (1, 0x02f, 25, True),
    'fast_b_iir_d_1_b2': (1, 0x033, 25, True),
    'fast_b_y_limit_1_min': (1, 0x037, 25, True),
    'fast_b_y_limit_1_max': (1, 0x03b, 25, True),
    'fast_b_x_limit_2_min': (1, 0x03f, 25, True),
    'fast_b_x_limit_2_max': (1, 0x043, 25, True),
    'fast_b_iir_c_2_z0': (1, 0x047, 27, True),
    'fast_b_iir_c_2_a1': (1, 0x04b, 25, True),
    'fast_b_iir_c_2_b0': (1, 0x04f, 25, True),
    'fast_b_iir_c_2_b1': (1, 0x053, 25, True),
    'fast_b_iir_d_2_z0': (1, 0x057, 27, True),
    'fast_b_iir_d_2_a1': (1, 0x05b, 25, True),
    'fast_b_iir_d_2_a2': (1, 0x05f, 25, True),
    'fast_b_iir_d_2_b0': (1, 0x063, 25, True),
    'fast_b_iir_d_2_b1': (1, 0x067, 25, True),
    'fast_b_iir_d_2_b2': (1, 0x06b, 25, True),
    'fast_b_y_limit_2_min': (1, 0x06f, 25, True),
    'fast_b_y_limit_2_max': (1, 0x073, 25, True),
    'fast_b_x_clr': (1, 0x077, 1, True),
    'fast_b_x_max': (1, 0x078, 25, False),
    'fast_b_x_min': (1, 0x07c, 25, False),
    'fast_b_out_i_clr': (1, 0x080, 1, True),
    'fast_b_out_i_max': (1, 0x081, 25, False),
    'fast_b_out_i_min': (1, 0x085, 25, False),
    'fast_b_out_q_clr': (1, 0x089, 1, True),
    'fast_b_out_q_max': (1, 0x08a, 25, False),
    'fast_b_out_q_min': (1, 0x08e, 25, False),
    'fast_b_dx_sel': (1, 0x092, 4, True),
    'fast_b_dy_sel': (1, 0x093, 4, True),
    'gpio_n_ins': (30, 0x000, 8, False),
    'gpio_n_outs': (30, 0x001, 8, True),
    'gpio_n_oes': (30, 0x002, 8, True),
    'gpio_n_state': (30, 0x003, 14, False),
    'gpio_n_state_clr': (30, 0x005, 1, True),
    'gpio_n_do0_en': (30, 0x006, 14, True),
    'gpio_n_do1_en': (30, 0x008, 14, True),
    'gpio_n_do2_en': (30, 0x00a, 14, True),
    'gpio_n_do3_en': (30, 0x00c, 14, True),
    'gpio_n_do4_en': (30, 0x00e, 14, True),
    'gpio_n_do5_en': (30, 0x010, 14, True),
    'gpio_n_do6_en': (30, 0x012, 14, True),
    'gpio_n_do7_en': (30, 0x014, 14, True),
    'gpio_p_ins': (31, 0x000, 8, False),
    'gpio_p_outs': (31, 0x001, 8, True),
    'gpio_p_oes': (31, 0x002, 8, True),
    'logic_dual_channel': (8, 0x000, 1, True),
    'logic_mod_channel': (8, 0x001, 1, True),
    'logic_control_channel': (8, 0x002, 1, True),
    'logic_sweep_channel': (8, 0x003, 2, True),
    'logic_slow_control_channel': (8, 0x004, 2, True),
    'logic_pid_only_mode': (8, 0x005, 1, True),
    'logic_chain_a_factor': (8, 0x006, 9, True),
    'logic_chain_b_factor': (8, 0x008, 9, True),
    'logic_chain_a_offset': (8, 0x00a, 14, True),
    'logic_chain_b_offset': (8, 0x00c, 14, True),
    'logic_combined_offset': (8, 0x00e, 14, True),
    'logic_out_offset': (8, 0x010, 14, True),
    'logic_slow_decimation': (8, 0x012, 5, True),
    'logic_analog_out_1': (8, 0x013, 15, True),
    'logic_analog_out_2': (8, 0x015, 15, True),
    'logic_analog_out_3': (8, 0x017, 15, True),
    'logic_slow_value': (8, 0x019, 14, False),
    'logic_mod_amp': (8, 0x01b, 14, True),
    'logic_mod_freq': (8, 0x01d, 32, True),
    'logic_sweep_step': (8, 0x021, 30, True),
    'logic_sweep_min': (8, 0x025, 14, True),
    'logic_sweep_max': (8, 0x027, 14, True),
    'logic_sweep_run': (8, 0x029, 1, True),
    'logic_sweep_pause': (8, 0x02a, 1, True),
    'logic_limit_error_signal_min': (8, 0x02b, 25, True),
    'logic_limit_error_signal_max': (8, 0x02f, 25, True),
    'logic_limit_fast1_min': (8, 0x033, 14, True),
    'logic_limit_fast1_max': (8, 0x035, 14, True),
    'logic_limit_fast2_min': (8, 0x037, 14, True),
    'logic_limit_fast2_max': (8, 0x039, 14, True),
    'logic_pid_setpoint': (8, 0x03b, 25, True),
    'logic_pid_kp': (8, 0x03f, 14, True),
    'logic_pid_ki': (8, 0x041, 14, True),
    'logic_pid_reset': (8, 0x043, 1, True),
    'logic_pid_kd': (8, 0x044, 14, True),
    'logic_autolock_robust_time_scale': (8, 0x046, 14, True),
    'logic_autolock_robust_N_instructions': (8, 0x048, 5, True),
    'logic_autolock_robust_final_wait_time': (8, 0x049, 14, True),
    'logic_autolock_robust_peak_height_0': (8, 0x04b, 28, True),
    'logic_autolock_robust_peak_height_1': (8, 0x04f, 28, True),
    'logic_autolock_robust_peak_height_2': (8, 0x053, 28, True),
    'logic_autolock_robust_peak_height_3': (8, 0x057, 28, True),
    'logic_autolock_robust_peak_height_4': (8, 0x05b, 28, True),
    'logic_autolock_robust_peak_height_5': (8, 0x05f, 28, True),
    'logic_autolock_robust_peak_height_6': (8, 0x063, 28, True),
    'logic_autolock_robust_peak_height_7': (8, 0x067, 28, True),
    'logic_autolock_robust_peak_height_8': (8, 0x06b, 28, True),
    'logic_autolock_robust_peak_height_9': (8, 0x06f, 28, True),
    'logic_autolock_robust_peak_height_10': (8, 0x073, 28, True),
    'logic_autolock_robust_peak_height_11': (8, 0x077, 28, True),
    'logic_autolock_robust_peak_height_12': (8, 0x07b, 28, True),
    'logic_autolock_robust_peak_height_13': (8, 0x07f, 28, True),
    'logic_autolock_robust_peak_height_14': (8, 0x083, 28, True),
    'logic_autolock_robust_peak_height_15': (8, 0x087, 28, True),
    'logic_autolock_robust_peak_height_16': (8, 0x08b, 28, True),
    'logic_autolock_robust_peak_height_17': (8, 0x08f, 28, True),
    'logic_autolock_robust_peak_height_18': (8, 0x093, 28, True),
    'logic_autolock_robust_peak_height_19': (8, 0x097, 28, True),
    'logic_autolock_robust_peak_height_20': (8, 0x09b, 28, True),
    'logic_autolock_robust_peak_height_21': (8, 0x09f, 28, True),
    'logic_autolock_robust_peak_height_22': (8, 0x0a3, 28, True),
    'logic_autolock_robust_peak_height_23': (8, 0x0a7, 28, True),
    'logic_autolock_robust_peak_height_24': (8, 0x0ab, 28, True),
    'logic_autolock_robust_peak_height_25': (8, 0x0af, 28, True),
    'logic_autolock_robust_peak_height_26': (8, 0x0b3, 28, True),
    'logic_autolock_robust_peak_height_27': (8, 0x0b7, 28, True),
    'logic_autolock_robust_peak_height_28': (8, 0x0bb, 28, True),
    'logic_autolock_robust_peak_height_29': (8, 0x0bf, 28, True),
    'logic_autolock_robust_peak_height_30': (8, 0x0c3, 28, True),
    'logic_autolock_robust_peak_height_31': (8, 0x0c7, 28, True),
    'logic_autolock_robust_wait_for_0': (8, 0x0cb, 14, True),
    'logic_autolock_robust_wait_for_1': (8, 0x0cd, 14, True),
    'logic_autolock_robust_wait_for_2': (8, 0x0cf, 14, True),
    'logic_autolock_robust_wait_for_3': (8, 0x0d1, 14, True),
    'logic_autolock_robust_wait_for_4': (8, 0x0d3, 14, True),
    'logic_autolock_robust_wait_for_5': (8, 0x0d5, 14, True),
    'logic_autolock_robust_wait_for_6': (8, 0x0d7, 14, True),
    'logic_autolock_robust_wait_for_7': (8, 0x0d9, 14, True),
    'logic_autolock_robust_wait_for_8': (8, 0x0db, 14, True),
    'logic_autolock_robust_wait_for_9': (8, 0x0dd, 14, True),
    'logic_autolock_robust_wait_for_10': (8, 0x0df, 14, True),
    'logic_autolock_robust_wait_for_11': (8, 0x0e1, 14, True),
    'logic_autolock_robust_wait_for_12': (8, 0x0e3, 14, True),
    'logic_autolock_robust_wait_for_13': (8, 0x0e5, 14, True),
    'logic_autolock_robust_wait_for_14': (8, 0x0e7, 14, True),
    'logic_autolock_robust_wait_for_15': (8, 0x0e9, 14, True),
    'logic_autolock_robust_wait_for_16': (8, 0x0eb, 14, True),
    'logic_autolock_robust_wait_for_17': (8, 0x0ed, 14, True),
    'logic_autolock_robust_wait_for_18': (8, 0x0ef, 14, True),
    'logic_autolock_robust_wait_for_19': (8, 0x0f1, 14, True),
    'logic_autolock_robust_wait_for_20': (8, 0x0f3, 14, True),
    'logic_autolock_robust_wait_for_21': (8, 0x0f5, 14, True),
    'logic_autolock_robust_wait_for_22': (8, 0x0f7, 14, True),
    'logic_autolock_robust_wait_for_23': (8, 0x0f9, 14, True),
    'logic_autolock_robust_wait_for_24': (8, 0x0fb, 14, True),
    'logic_autolock_robust_wait_for_25': (8, 0x0fd, 14, True),
    'logic_autolock_robust_wait_for_26': (8, 0x0ff, 14, True),
    'logic_autolock_robust_wait_for_27': (8, 0x101, 14, True),
    'logic_autolock_robust_wait_for_28': (8, 0x103, 14, True),
    'logic_autolock_robust_wait_for_29': (8, 0x105, 14, True),
    'logic_autolock_robust_wait_for_30': (8, 0x107, 14, True),
    'logic_autolock_robust_wait_for_31': (8, 0x109, 14, True),
    'logic_autolock_fast_target_position': (8, 0x10b, 14, True),
    'logic_autolock_request_lock': (8, 0x10d, 1, True),
    'logic_autolock_autolock_mode': (8, 0x10e, 2, True),
    'logic_autolock_lock_running': (8, 0x10f, 1, False),
    'logic_raw_acquisition_iir_z0': (8, 0x110, 27, True),
    'logic_raw_acquisition_iir_a1': (8, 0x114, 25, True),
    'logic_raw_acquisition_iir_a2': (8, 0x118, 25, True),
    'logic_raw_acquisition_iir_a3': (8, 0x11c, 25, True),
    'logic_raw_acquisition_iir_a4': (8, 0x120, 25, True),
    'logic_raw_acquisition_iir_a5': (8, 0x124, 25, True),
    'logic_raw_acquisition_iir_b0': (8, 0x128, 25, True),
    'logic_raw_acquisition_iir_b1': (8, 0x12c, 25, True),
    'logic_raw_acquisition_iir_b2': (8, 0x130, 25, True),
    'logic_raw_acquisition_iir_b3': (8, 0x134, 25, True),
    'logic_raw_acquisition_iir_b4': (8, 0x138, 25, True),
    'logic_raw_acquisition_iir_b5': (8, 0x13c, 25, True),
    'logic_control_signal_clr': (8, 0x140, 1, True),
    'logic_control_signal_max': (8, 0x141, 25, False),
    'logic_control_signal_min': (8, 0x145, 25, False),
    'logic_combined_error_signal_clr': (8, 0x149, 1, True),
    'logic_combined_error_signal_max': (8, 0x14a, 25, False),
    'logic_combined_error_signal_min': (8, 0x14e, 25, False),
    'logic_combined_error_signal_filtered_clr': (8, 0x152, 1, True),
    'logic_combined_error_signal_filtered_max': (8, 0x153, 25, False),
    'logic_combined_error_signal_filtered_min': (8, 0x157, 25, False),
    'scopegen_external_trigger': (6, 0x000, 1, True),
    'scopegen_dac_a_clr': (6, 0x001, 1, True),
    'scopegen_dac_a_max': (6, 0x002, 25, False),
    'scopegen_dac_a_min': (6, 0x006, 25, False),
    'scopegen_dac_b_clr': (6, 0x00a, 1, True),
    'scopegen_dac_b_max': (6, 0x00b, 25, False),
    'scopegen_dac_b_min': (6, 0x00f, 25, False),
    'scopegen_adc_a_sel': (6, 0x013, 4, True),
    'scopegen_adc_b_sel': (6, 0x014, 4, True),
    'scopegen_adc_a_q_sel': (6, 0x015, 4, True),
    'scopegen_adc_b_q_sel': (6, 0x016, 4, True),
    'slow_chain_pid_setpoint': (2, 0x000, 14, True),
    'slow_chain_pid_kp': (2, 0x002, 14, True),
    'slow_chain_pid_ki': (2, 0x004, 14, True),
    'slow_chain_pid_reset': (2, 0x006, 1, True),
    'slow_chain_pid_kd': (2, 0x007, 14, True),
    'slow_chain_limit_min': (2, 0x009, 14, True),
    'slow_chain_limit_max': (2, 0x00b, 14, True),
    'slow_chain_out_clr': (2, 0x00d, 1, True),
    'slow_chain_out_max': (2, 0x00e, 25, False),
    'slow_chain_out_min': (2, 0x012, 25, False),
    'xadc_temp': (29, 0x000, 12, False),
    'xadc_v': (29, 0x002, 12, False),
    'xadc_a': (29, 0x004, 12, False),
    'xadc_b': (29, 0x006, 12, False),
    'xadc_c': (29, 0x008, 12, False),
    'xadc_d': (29, 0x00a, 12, False),
}
states = ['force', 'di0', 'di1', 'di2', 'di3', 'di4', 'di5', 'di6', 'di7', 'robustwatching', 'robustturn_on_lock', 'robustsign_equal', 'robustover_threshold', 'robustwaited_long_enough']
signals = ['zero', 'fast_a_x', 'fast_a_out_i', 'fast_a_out_q', 'fast_b_x', 'fast_b_out_i', 'fast_b_out_q', 'slow_chain_out', 'scopegen_dac_a', 'scopegen_dac_b', 'logic_control_signal', 'logic_combined_error_signal', 'logic_combined_error_signal_filtered']
